package ma.cdm.compteRenduVO;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import org.springframework.util.CollectionUtils;

public class CompteRenduVO implements Externalizable, Serializable {

	private String compteRenduID;
	private String compteRenduObject;
	private Date dateReunion;
	private String template;
	private List<PersonneVO> participants;
	private List<PersonneVO> participantsExternes;
	private List<PersonneVO> participantsInternes;
	private List<PieceJointeVO> piecesJointes;
	
	private PersonneVO president;
    private List<PointVO> points;
    private ComiteVO comite;
    
    
   	
    
	public CompteRenduVO() {
		super();
	}

	public CompteRenduVO(String id, String objet, Date date) {
		compteRenduID = id;
		compteRenduObject = objet;
		dateReunion = date;
	}
    
	
	public List<PieceJointeVO> getPiecesJointes() {
		return piecesJointes;
	}

	public void setPiecesJointes(List<PieceJointeVO> piecesJointes) {
		this.piecesJointes = piecesJointes;
	}

	public JRDataSource getPointsJRDatasource()
	{
		  JRBeanCollectionDataSource beanColDataSource =
		            new JRBeanCollectionDataSource(points);
		  return beanColDataSource;
	}
	
	@SuppressWarnings("unchecked")
	public List<PointVO> getListPoints()
	{
		  return CollectionUtils.arrayToList(points);
	}
	


	public List<PersonneVO> getParticipants() {
		return participants;
	}

	public void setParticipants(List<PersonneVO> participants) {
		this.participants = participants;
	}

	public List<PointVO> getPoints() {
		return points;
	}

	public void setPoints(List<PointVO> points) {
		this.points = points;
	}

	public String getParticipantsString()
    {
    	String participantsStr="";
    	for (int i = 0; i < participants.size(); i++) {
    		if(participants.get(i).isPresent()){
    		   participantsStr=participantsStr+participants.get(i);
    		}
		}
    	return participantsStr;
    }
	
	public JRBeanCollectionDataSource getParticipantsJR() {
		 return new JRBeanCollectionDataSource(participants);
	}



	public List<PersonneVO> getParticipantsExternes() {
		return participantsExternes;
	}

	
	public List<PersonneVO> getParticipantsInternes() {
		return participantsInternes;
	}

	public void setParticipantsInternes(List<PersonneVO> participantsInternes) {
		this.participantsInternes = participantsInternes;
	}

	public void setParticipantsExternes(List<PersonneVO> participantsExternes) {
		this.participantsExternes = participantsExternes;
	}

	public PersonneVO getPresident() {
		return president;
	}

	public void setPresident(PersonneVO president) {
		this.president = president;
	}

	public ComiteVO getComite() {
   		return comite;
   	}

   	public void setComite(ComiteVO comite) {
   		this.comite = comite;
   	}
   	
	public String getCompteRenduID() {
		return compteRenduID;
	}

	public void setCompteRenduID(String compteRenduID) {
		this.compteRenduID = compteRenduID;
	}

	public String getCompteRenduObject() {
		return compteRenduObject;
	}

	public void setCompteRenduObject(String compteRenduObject) {
		this.compteRenduObject = compteRenduObject;
	}

	public Date getDateReunion() {
		return dateReunion;
	}

	public void setDateReunion(Date dateReunion) {
		this.dateReunion = dateReunion;
	}

	
	public String getTemplate() {
		return template;
	}

	public void setTemplate(String template) {
		this.template = template;
	}

	public void writeExternal(ObjectOutput output) throws IOException {
		 output.writeObject(comite);
		 output.writeObject(compteRenduID);
         output.writeObject(compteRenduObject);
         output.writeObject(dateReunion);
         output.writeObject(participants);
         output.writeObject(participantsExternes);
         output.writeObject(participantsInternes);
         output.writeObject(piecesJointes);
         output.writeObject(points);
         output.writeObject(president);
         output.writeObject(template);
	}

	
	@SuppressWarnings("unchecked")
	public void readExternal(ObjectInput input) throws IOException,
			ClassNotFoundException {
		 comite =(ComiteVO) input.readObject() ;
		 compteRenduID =(String) input.readObject() ;
         compteRenduObject =(String) input.readObject()  ;
         dateReunion =(Date) input.readObject()  ;
         participants =(List<PersonneVO>)input.readObject();
         participantsExternes =(List<PersonneVO>)input.readObject();
         participantsInternes = (List<PersonneVO>)input.readObject();
         piecesJointes = (List<PieceJointeVO>)input.readObject();
         points = (List<PointVO>)input.readObject();
         president =(PersonneVO) input.readObject();
         template = (String) input.readObject();
	}

}
